home *** CD-ROM | disk | FTP | other *** search
- /******************************/
- /* Tiny format loader */
- /* Copyright 1986 Tom Hudson */
- /******************************/
-
- #include <osbind.h>
-
- /**********************/
- /* GLOBAL VARIABLES */
- /**********************/
-
- int contrl[12];
- int intin[128];
- int ptsin[128];
- int intout[128];
- int ptsout[128];
-
- char bad_file[]=
- "[1][ |This file has an incorrect | format!| ][ Sorry ]";
-
- int colors[16];
- unsigned int ctl_cnt,dat_cnt;
- long act_ctl,act_dat;
- char head1[4],*ctl_ptr,picrez;
- int *dat_ptr,*sc_data,sc_ix;
-
- /* temporary work buffers */
-
- static char ctlbuf[10680];
- static int datbuf[16000];
-
- /* Set up your screen buffer (32000 bytes, aligned on 256 byte boundary) */
- /* Place address in 'screen'. */
-
- long screen;
-
- /***************************************************/
- /* Open .TNY file, then call do_tiny(file_handle); */
- /***************************************************/
-
- do_tiny(fhand)
- int fhand;
- {
- Fread(fhand,1L,&picrez);
- if(picrez>2)
- {
- picrez-=3;
- Fread(fhand,4L,head1); /* head1 holds color cycling data */
- }
- Fread(fhand,32L,colors); /* palette */
- Fread(fhand,2L,&ctl_cnt); /* control size in bytes */
- Fread(fhand,2L,&dat_cnt); /* data size in words */
-
- if(ctl_cnt>10667 || dat_cnt>16000)
- {
- form_alert(1,bad_file);
- }
- else
- {
- act_ctl=Fread(fhand,(long)ctl_cnt,ctlbuf); /* Read control data */
- ctl_ptr=(char *)ctlbuf;
-
- dat_cnt*=2; /* convert to bytes */
- act_dat=Fread(fhand,(long)dat_cnt,datbuf); /* read image data */
- dat_ptr=(int *)datbuf;
-
- if(act_ctl==(long)ctl_cnt && act_dat==(long)dat_cnt)
- decompress();
- else
- form_alert(1,bad_file);
- }
- Fclose(fhand);
- }
-
- decompress()
- {
- register int ix,repct;
- register char ctlbyte;
-
- sc_ix=0;
- sc_data=(int *)screen;
-
- for(ix=0; ix<ctl_cnt; ++ix)
- {
- ctlbyte=ctl_ptr[ix];
- if(ctlbyte<0)
- {
- unique((int)(-ctlbyte));
- }
- else
- if(ctlbyte==0 || ctlbyte==1)
- {
- repct=(int)ctl_ptr[++ix];
- repct=(repct<<8) | ((int)ctl_ptr[++ix] & 0x00ff);
- if(ctlbyte==0)
- {
- repeat(repct);
- }
- else
- {
- unique(repct);
- }
- }
- else
- {
- repeat((int)ctlbyte);
- }
- }
- }
-
- unique(count)
- int count;
- {
- register int ix,data;
-
- for(ix=0; ix<count; ++ix)
- {
- toscreen(*dat_ptr);
- dat_ptr++;
- }
- }
-
- repeat(count)
- int count;
- {
- register int ix,data;
-
- data= *dat_ptr;
- dat_ptr++;
- for(ix=0; ix<count; ++ix)
- toscreen(data);
- }
-
- toscreen(data)
- int data;
- {
- sc_data[sc_ix]=data;
- sc_ix+=80;
- if(sc_ix>15999)
- {
- sc_ix-=15996;
- if(sc_ix>79)
- sc_ix-=79;
- }
- }